#include "udp_sample.h"

int main(void)
{
	struct sockaddr_in sock_server;
	int s, i;
	socklen_t socklen = sizeof(struct sockaddr_in);
	char buf[BUFLEN];

	if ((s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) {
		diep("socket");
	}

	sock_server.sin_family = AF_INET;
	sock_server.sin_port = htons(PORT);

	if (inet_aton("127.0.0.1", &(sock_server.sin_addr)) == 0) {
		fprintf(stderr, "inet_aton() failed\n");
		exit(1);
	}

	for (i = 0; i < 3; i++) {
		printf("Sending packet %d\n", i);
		sprintf(buf, "This is packet %d\n", i);

		if (sendto(s, buf, BUFLEN, 0,
					(struct sockaddr *) &sock_server, socklen) == -1) {
			diep("sendto()");
		}
	}

	close(s);
	return 0;
}
